import axios from "axios";
import nProgress from "nprogress";
import 'nprogress/nprogress.css'
import store from '@/store'

const requests= axios.create({
    baseURL:'/api',
    timeout:5000,
})
requests.interceptors.request.use((config)=>{
    // 请求头中添加游客的uuid
    if(store.state.detail.uuid){
        config.headers.userTempId=store.state.detail.uuid
        config.headers.token=store.state.user.token
    }
    // 添加进度条
    nProgress.start()
    return config
})
requests.interceptors.response.use((res)=>{
    nProgress.done()
    return res.data
},(error)=>{
    // 终止Promise链
    return Promise.reject(new Error('fail'))
})
export default requests